﻿
using WCYCReader.Models;
using System;
using WCYCReader.Utility;
namespace WCYCReader.Main
{
    public class SaveReaderHistory
    {
        //public static void Delete(BookList_M blm)
        //{
        //    BookList_M valueFromSettings = new BookList_M();
        //    BookList_M t_m2 = new BookList_M();
        //    BookList_M t_m3 = new BookList_M();
        //    if (SettingHelper.IsSettings("ReaderHistory1"))
        //    {
        //        valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory1") as BookList_M;
        //    }
        //    if (SettingHelper.IsSettings("ReaderHistory2"))
        //    {
        //        t_m2 = SettingHelper.GetValueFromSettings("ReaderHistory2") as BookList_M;
        //    }
        //    if (SettingHelper.IsSettings("ReaderHistory3"))
        //    {
        //        t_m3 = SettingHelper.GetValueFromSettings("ReaderHistory3") as BookList_M;
        //    }
        //    if (t_m3.str_Id_M == blm.str_Id_M)
        //    {
        //        SettingHelper.DeleteSettings("ReaderHistory3");
        //    }
        //    else if (t_m2.str_Id_M == blm.str_Id_M)
        //    {
        //        SettingHelper.DeleteSettings("ReaderHistory2");
        //        if (SettingHelper.IsSettings("ReaderHistory3"))
        //        {
        //            SettingHelper.SaveInToSettings("ReaderHistory2", t_m3);
        //            SettingHelper.DeleteSettings("ReaderHistory3");
        //        }
        //    }
        //    else if (valueFromSettings.str_Id_M == blm.str_Id_M)
        //    {
        //        SettingHelper.DeleteSettings("ReaderHistory1");
        //        if (SettingHelper.IsSettings("ReaderHistory3"))
        //        {
        //            SettingHelper.SaveInToSettings("ReaderHistory1", t_m2);
        //            SettingHelper.SaveInToSettings("ReaderHistory2", t_m3);
        //            SettingHelper.DeleteSettings("ReaderHistory3");
        //        }
        //        else if (SettingHelper.IsSettings("ReaderHistory2"))
        //        {
        //            SettingHelper.SaveInToSettings("ReaderHistory1", t_m2);
        //            SettingHelper.DeleteSettings("ReaderHistory2");
        //        }
        //    }
        //}

        //public static void Save(BookList_M blm)
        //{
        //    Delete(blm);
        //    if (SettingHelper.IsSettings("ReaderHistory2"))
        //    {
        //        BookList_M valueFromSettings = new BookList_M();
        //        valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory2") as BookList_M;
        //        SettingHelper.SaveInToSettings("ReaderHistory3", valueFromSettings);
        //    }
        //    if (SettingHelper.IsSettings("ReaderHistory1"))
        //    {
        //        BookList_M t_m2 = new BookList_M();
        //        t_m2 = SettingHelper.GetValueFromSettings("ReaderHistory1") as BookList_M;
        //        SettingHelper.SaveInToSettings("ReaderHistory2", t_m2);
        //    }
        //    SettingHelper.SaveInToSettings("ReaderHistory1", blm);
        //}

        public static void Delete(BookList_M blm)
        {
            BookList_M valueFromSettings = new BookList_M(), t_m2 = new BookList_M(), t_m3 = new BookList_M(), t_m4 = new BookList_M();
            if (SettingHelper.IsSettings("ReaderHistory1"))
            {
                valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory1") as BookList_M;
            }
            if (SettingHelper.IsSettings("ReaderHistory2"))
            {
                t_m2 = SettingHelper.GetValueFromSettings("ReaderHistory2") as BookList_M;
            }
            if (SettingHelper.IsSettings("ReaderHistory3"))
            {
                t_m3 = SettingHelper.GetValueFromSettings("ReaderHistory3") as BookList_M;
            }
            if (SettingHelper.IsSettings("ReaderHistory4"))
            {
                t_m4 = SettingHelper.GetValueFromSettings("ReaderHistory4") as BookList_M;
            }
            //
            if (t_m4.str_Id_M == blm.str_Id_M)
            {
                SettingHelper.DeleteSettings("ReaderHistory4");
            }
            else if (t_m3.str_Id_M == blm.str_Id_M)
            {
                SettingHelper.DeleteSettings("ReaderHistory3");
                if (SettingHelper.IsSettings("ReaderHistory4"))
                {
                    SettingHelper.SaveInToSettings("ReaderHistory3", t_m4);
                    SettingHelper.DeleteSettings("ReaderHistory4");
                }
            }
            else if (t_m2.str_Id_M == blm.str_Id_M)
            {
                SettingHelper.DeleteSettings("ReaderHistory2");
                if (SettingHelper.IsSettings("ReaderHistory3"))
                {
                    SettingHelper.SaveInToSettings("ReaderHistory2", t_m3);
                    SettingHelper.DeleteSettings("ReaderHistory3");
                }
            }
            else if (valueFromSettings.str_Id_M == blm.str_Id_M)
            {
                SettingHelper.DeleteSettings("ReaderHistory1");
                if (SettingHelper.IsSettings("ReaderHistory4"))
                {
                    SettingHelper.SaveInToSettings("ReaderHistory1", t_m2);
                    SettingHelper.SaveInToSettings("ReaderHistory2", t_m3);
                    SettingHelper.SaveInToSettings("ReaderHistory3", t_m4);
                    SettingHelper.DeleteSettings("ReaderHistory4");
                }
                else if (SettingHelper.IsSettings("ReaderHistory3"))
                {
                    SettingHelper.SaveInToSettings("ReaderHistory1", t_m2);
                    SettingHelper.SaveInToSettings("ReaderHistory2", t_m3);
                    SettingHelper.DeleteSettings("ReaderHistory3");
                }
                else if (SettingHelper.IsSettings("ReaderHistory2"))
                {
                    SettingHelper.SaveInToSettings("ReaderHistory1", t_m2);
                    SettingHelper.DeleteSettings("ReaderHistory2");
                }
            }
        }

        public static void Save(BookList_M blm)
        {
            Delete(blm);
            if (SettingHelper.IsSettings("ReaderHistory3"))
            {
                BookList_M valueFromSettings = new BookList_M();
                valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory3") as BookList_M;
                SettingHelper.SaveInToSettings("ReaderHistory4", valueFromSettings);
            }
            if (SettingHelper.IsSettings("ReaderHistory2"))
            {
                BookList_M valueFromSettings = new BookList_M();
                valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory2") as BookList_M;
                SettingHelper.SaveInToSettings("ReaderHistory3", valueFromSettings);
            }
            if (SettingHelper.IsSettings("ReaderHistory1"))
            {
                BookList_M valueFromSettings = new BookList_M();
                valueFromSettings = SettingHelper.GetValueFromSettings("ReaderHistory1") as BookList_M;
                SettingHelper.SaveInToSettings("ReaderHistory2", valueFromSettings);
            }
            SettingHelper.SaveInToSettings("ReaderHistory1", blm);
        }

    }
}

